<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/11
 * Time: 17:21
 */
class Prize_every_day_model extends CI_Model
{
    private $_table = 'prize_every_day';

    /**
     * 今日剩余奖品数量减一
     * @param unknown $prize_id
     */
    public function decreaseTodayNum($params)
    {
        $this->db->set('surplus_quantity',"surplus_quantity - 1",false);
        if ( !empty($params->winners_user)) {
            $this->db->set('winners_user', $params->winners_user);
        }

        if ( !empty($params->time_slot)) {
            $this->db->set('time_slot', $params->time_slot);
        }
        
        $this->db->where('prize_id', $params->prize_id);
        $this->db->where('date', date('Y-m-d'));
        return $this->db->update($this->_table);
    }

    public function findByPrizeId($prizeId)
    {
        $this->db->select('surplus_quantity');
        $this->db->from($this->_table);
        $this->db->where('prize_id', $prizeId);
        $this->db->where('date', date('Y-m-d'));
        $this->db->limit(1);
        return $this->db->get();
    }

}